export const state = () => ({
    historyList: [],
    postList: []
})
import moment from 'moment'
export const mutations = {
    addHistory(state, data) {
        // 可以做判断, 如果不存在完全一样的数据在进行添加
        let isUnique = true
        state.historyList.forEach(history => {
            if (
                history.departCity == data.departCity &&
                history.departCode == data.departCode &&
                history.destCity == data.destCity &&
                history.destCode == data.destCode &&
                history.departDate == data.departDate
            ) {
                isUnique = false
            }
        });

        if (isUnique) {
            state.historyList.unshift(data)
        }
    },
      addDraftList (state, data) {
    // console.log(data)
    const newData = { ...data.form }
    console.log(newData)
    // 判断是否有id，如果有id就覆盖原来的，没有就追加
    if (data.id || data.id === 0) {
      state.postList.splice(data.id, 1, newData)
    } else {
      state.postList.push(newData)
        }
        

    console.log(state)
    state.postList.forEach((element) => {
      element.time = new Date()
      element.time = moment(element.time).format('YYYY-MM-DD')
    })
  },
  delDraft(state, index) {
        state.postList.splice(index,1)
      }
}
